package com.honeywen.mymvc.leetcode;

/**
 * 434. 字符串中的单词数
 * https://leetcode-cn.com/problems/number-of-segments-in-a-string/
 * @author wangwei
 * @date 2019/3/4
 */
public class CountSegmentTest {

    public static void main(String[] args) {


//        System.out.println(countSegments("Hello, my name is John")); // 5
        System.out.println(countSegments(", , , ,        a, eaefa")); //6



    }

    public static int countSegments(String s) {

//        if (s == null || s.length() == 0) {
//            return 0;
//        }
        int count = 0;
        for (String str : s.split(" ")) {

            if (str.matches("[^\\s]+")) {
                count++;
            }

        }
        return count;

    }
}
